#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, m, q, c[100005], a[100005][6];
// -fsanitize=undefined
namespace CR200J {
	int dp[100005][6], lst;
	int dfs(int l, int r, int x) {
		if (l == r + 1) return x == 0 ? 0 : -(1ll << 60);
		if (dp[l][x] != -1) return dp[l][x];
		int cst = (x ? a[l][x] : a[l][c[l]]), ans = dfs(l + 1, r, x);
		if (x) {
			if (c[l] == x) ans = max(ans, dfs(l + 1, r, 0));
		} else {
			ans = max(ans, dfs(l + 1, r, c[l]));
		}
		return dp[l][x] = ans + cst;
	}
	int solve(int l, int r) {
		for (int i = l; i <= r + 1; ++i) {
			memset(dp, 255, sizeof(dp));
		}
		return dfs(l, r, 0);
	}
	void main() {
		cout << (lst = solve(1, n)) << "\n";
		while (q--) {
			int o, l, r;
			cin >> o >> l >> r;
			l ^= lst; r ^= lst;
			if (o == 1) {
				c[l] = r;
			} else {
				cout << (lst = solve(l, r)) << "\n";
			}
		}
	}
}

namespace CR400AF {
	int lst;
	struct Mat {
		int mat[6][6];
		Mat operator * (const Mat &ma) const {
			Mat res = {};
			memset(res.mat, 197, sizeof(res.mat));
			for (int i = 0; i <= m; ++i) {
				for (int j = 0; j <= m; ++j) {
					for (int k = 0; k <= m; ++k) {
						if (mat[i][k] >= 0 && ma.mat[k][j] >= 0)
						res.mat[i][j] = max(res.mat[i][j], mat[i][k] + ma.mat[k][j]);
					}
				}
			}
			for (int i = 0; i <= m; ++i) {
				for (int j = 0; j <= m; ++j) {
					if (res.mat[i][j] < 0) {
						res.mat[i][j] = -(1ll << 60);
					}
				}
			}	
			return res;
		}
	};
	Mat I() {
		Mat res = {};
		memset(res.mat, 197, sizeof(res.mat));
		for (int i = 0; i <= m; ++i) {
			res.mat[i][i] = 0;
		}
		return res;
	}
	Mat getm(int i) {
		Mat nows = {};
		memset(nows.mat, 197, sizeof(nows.mat));
		for (int x = 0; x <= m; ++x) {
			int cst = (x ? a[i][x] : a[i][c[i]]);
			nows.mat[x][x] = cst;
			if (x) {
				if (c[i] == x) {
					nows.mat[x][0] = cst;
				}
			} else {
				nows.mat[x][c[i]] = cst;
			}
		}
		return nows;
	}
	struct SGT {
		Mat res[400001];
#define ls(p) (p << 1)
#define rs(p) (p << 1 | 1)
		void push_up(int i) {
			res[i] = res[ls(i)] * res[rs(i)];
		}
		void build(int i, int l, int r) {
			if (l == r) {
				res[i] = getm(l);
				return;
			}
			int mid = (l + r) / 2;
			build(ls(i), l, mid);
			build(rs(i), mid + 1, r);
			push_up(i);
		}
		void update(int i, int l, int r, int qpos) {
			if (l > qpos || r < qpos) return;
			if (l == r) {
				assert(l == qpos);
				res[i] = getm(l);
				return;
			}
			int mid = (l + r) / 2;
			update(ls(i), l, mid, qpos);
			update(rs(i), mid + 1, r, qpos);
			push_up(i);
		}
		Mat query(int i, int l, int r, int ql, int qr) {
			if (l > qr || r < ql) return I();
			if (l >= ql && r <= qr) return res[i];
			int mid = (l + r) / 2;
			return query(ls(i), l, mid, ql, qr) * query(rs(i), mid + 1, r, ql, qr);
		}
	} t;
	int solve(int l, int r) {
/*
   [  0      [  
      1    * 
	  2  ]
*//*
		Mat res = {};
		memset(res.mat, 197, sizeof(res.mat));
	//	cout << res.mat[0][0] << "\n";
		for (int i = 0; i <= m; ++i) {
			res.mat[i][i] = 0;
		}
		for (int i = l; i <= r; ++i) {
			Mat nows = {};
			memset(nows.mat, 196, sizeof(nows.mat));
			for (int x = 0; x <= m; ++x) {
				int cst = (x ? a[i][x] : a[i][c[i]]);
				nows.mat[x][x] = cst;
				if (x) {
					if (c[i] == x) {
						nows.mat[x][0] = cst;
					}
				} else {
					nows.mat[x][c[i]] = cst;
				}
			}
		//	cout << i << " muls: " << endl;
			for (int i = 0; i <= m; ++i) {
				for (int j = 0; j <= m; ++j) {
				//	cout << nows.mat[i][j] << " \n"[j == m];
				}
			}
			res = res * nows;
		//	cout << " eqt \n";
			for (int i = 0; i <= m; ++i) {
				for (int j = 0; j <= m; ++j) {
				//	cout << res.mat[i][j] << " \n"[j == m];
				}
			}

		}
		return res.mat[0][0];*/
		return t.query(1, 1, n, l, r).mat[0][0];
	}
	void main() {
		for (int i = 0; i <= 400000; ++i) {
			t.res[i] = I();
		}
		t.build(1, 1, n);
		cout << (lst = solve(1, n)) << "\n";
		for (int i = 1; i <= q; ++i) {
			int o, l, r;
			cin >> o >> l >> r;
			l ^= lst; r ^= lst;
			if (o == 1) {
				c[l] = r;
				t.update(1, 1, n, l);
			} else {
				cout << (lst = solve(l, r)) << "\n";
			}
		}
	}
}

signed main() {
	freopen("paint.in", "r", stdin); freopen("paint.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> c[i];
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> a[i][j];
		}
	}
	if (n * (q + 1) <= 1e6) {
		CR200J::main();
	} else CR400AF::main();
	return 0;
}
